package dao.auth.mybatis;

import java.util.List;
import java.util.Map;

import model.auth.Authorities;
import model.auth.Roles;
import model.auth.RolesAuthorities;

import org.springframework.stereotype.Repository;

import core.base.page.Page;
import core.base.page.PageRequest;
import dao.MyBatisBaseDao;
import dao.auth.RolesAuthoritiesDao;

@Repository("auth.RolesAuthoritiesDao")
public class RolesAuthoritiesDaoImpl extends MyBatisBaseDao implements RolesAuthoritiesDao {

	public int deleteById(Long id) {
		return getSqlSessionTemplate().delete("auth.RolesAuthoritiesMapper.deleteById", id);
	}

	public RolesAuthorities getById(Long id) {
		return (RolesAuthorities) getSqlSessionTemplate().selectOne("auth.RolesAuthoritiesMapper.getById", id);
	}

	public int insert(RolesAuthorities model) {
		return getSqlSessionTemplate().insert("auth.RolesAuthoritiesMapper.insert", model);
	}

	public List<Authorities> getAuthoritiesByRoleId(Long roleId) {
		List<Authorities> auths = getSqlSessionTemplate().selectList("auth.RolesAuthoritiesMapper.getAuthoritiesByRoleId", roleId);
		return auths;
	}

	public List<Roles> getRolesByAuthCode(String authCode) {
		List<Roles> roles = getSqlSessionTemplate().selectList("auth.RolesAuthoritiesMapper.getRolesByAuthCode", authCode);
		return roles;
	}

	public Page<Authorities> queryAuthoritiesForPage(PageRequest<Map> pageReq) {
		return super.queryForPage(pageReq, "auth.RolesAuthoritiesMapper.queryAuthoritiesForPage");
	}

	public Page<Roles> queryRolesForPage(PageRequest<Map> pageReq) {
		return super.queryForPage(pageReq, "auth.RolesAuthoritiesMapper.queryRolesForPage");
	}

}
